package com.zp.business.controller.exam;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.business.entity.exam.bo.ExamItemBo;
import com.zp.business.entity.exam.vo.ExamItemVo;
import com.zp.business.service.exam.IExamItemService;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.excel.utils.ExcelUtil;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 检查申请子控制器
 * 前端访问路由地址为:/business/examItem
 *
 * @author zhang peng
 * @ date 2024-01-05
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/examItem")
public class ExamItemController extends BaseController {

    private final IExamItemService iExamItemService;

    /**
     * 查询检查申请子列表 (分页)
     */
    @SaCheckPermission("business:examItem:list")
    @GetMapping("/selectPage")
    public TableDataInfo<ExamItemVo> selectPage (ExamItemBo bo, PageQuery pageQuery) {
        return iExamItemService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询检查申请子列表 (不分页)
     */
    @SaCheckPermission("business:examItem:list")
    @GetMapping("/list")
    public R<List<ExamItemVo>> list (ExamItemBo bo) {
        List<ExamItemVo> list = iExamItemService.queryList(bo);
        return R.ok(list);
    }

    /**
     * 导出检查申请子列表
     */
    @SaCheckPermission("business:examItem:export")
    @Log(title = "检查申请子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export (ExamItemBo bo, HttpServletResponse response) {
        List<ExamItemVo> list = iExamItemService.queryList(bo);
        ExcelUtil.exportExcel(list, "检查申请子", ExamItemVo.class, response);
    }

    /**
     * 获取检查申请子详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:examItem:list")
    @GetMapping("/{id}")
    public R<ExamItemVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String id) {
        return R.ok(iExamItemService.queryById(id));
    }

    /**
     * 新增检查申请子
     */
    @SaCheckPermission("business:examItem:add")
    @Log(title = "检查申请子", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody ExamItemBo bo) {
        return toAjax(iExamItemService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改检查申请子
     */
    @SaCheckPermission("business:examItem:edit")
    @Log(title = "检查申请子", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody ExamItemBo bo) {
        return toAjax(iExamItemService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除检查申请子
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:examItem:remove")
    @Log(title = "检查申请子", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] ids) {
        return toAjax(iExamItemService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }

    /**
     * 修改收费状态
     *
     * @param id 主键
     */
//    @SaCheckPermission("business:examApply:remove")
//    @Log(title = "检查申请主", businessType = BusinessType.UPDATE)
//    @GetMapping("/itemRefundApplication/{id}/{chargeFlag}")
//    public R<Boolean> refundApplication (@NotEmpty(message = "主键不能为空") @PathVariable String id,
//                                         @NotEmpty(message = "收费类型不能为空") @PathVariable String chargeFlag) {
//        return R.ok(iExamItemService.refundApplication(id, chargeFlag));
//    }
}
